/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.view;

import br.com.documentar.controller.ProdutoController;
import br.com.documentar.interfacee.InterfaceView;
import br.com.documentar.model.CategoriaArvoreModel;
import br.com.documentar.model.ProdutoModel;
import br.com.documentar.util.UtilitariosCampos;
import br.com.documentar.util.setFiltroCampo;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Santos
 */
public class CategoriaArvoreView extends javax.swing.JFrame implements InterfaceView<br.com.documentar.model.CategoriaArvoreModel> {

    private br.com.documentar.controller.CategoriaArvoreController control = new br.com.documentar.controller.CategoriaArvoreController();
    private br.com.documentar.model.CategoriaArvoreModel model = control.getModel();

    /**
     * Creates new form CategoriaArvoreView No comboBox pai, mostrar uma arvore
     * de texto para facilitar a visualização dos dados exemplo: 1 - faturamneto
     * 2 - 2 Relatório 3 - 38 Resumo de Faturamento
     */
    public CategoriaArvoreView() {
        initComponents();
        Start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPaneManutencao = new javax.swing.JTabbedPane();
        panelConsulta = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        textFieldConsultar = new javax.swing.JTextField();
        jScrollPaneTable = new javax.swing.JScrollPane();
        jTableConsulta = new javax.swing.JTable();
        panelAbaACadastro = new javax.swing.JPanel();
        jScrollPaneManutencaoClienteA = new javax.swing.JScrollPane();
        jPanelManutencaoACadastro = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        textFieldCodigo = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        comboBoxProduto = new javax.swing.JComboBox();
        comboBoxCodigoPai = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        textFieldNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        textFieldCodigoProcesso = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        comboBoxTemFilho = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaObjetivo = new javax.swing.JTextArea();
        comboBoxAtivo = new javax.swing.JComboBox();
        panelAbaBCadastro = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        textAreaConsequenciaNaoUso = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        textAreaLinkVideo = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        textAreaPeriodicidade = new javax.swing.JTextArea();
        panelAbaRelatorio = new javax.swing.JPanel();
        toolBarManutencao = new javax.swing.JToolBar();
        buttonConsultar = new javax.swing.JButton();
        buttonNovo = new javax.swing.JButton();
        buttonEditar = new javax.swing.JButton();
        buttonExcluir = new javax.swing.JButton();
        buttonCancelar = new javax.swing.JButton();
        buttonGravar = new javax.swing.JButton();
        buttonRelatorio = new javax.swing.JButton();
        buttonAnterior = new javax.swing.JButton();
        buttonProximo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrar Categoria");

        jLabelNome.setText("Pesquisar:");

        jTableConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableConsulta.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTableConsulta.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableConsulta.getTableHeader().setReorderingAllowed(false);
        jScrollPaneTable.setViewportView(jTableConsulta);

        javax.swing.GroupLayout panelConsultaLayout = new javax.swing.GroupLayout(panelConsulta);
        panelConsulta.setLayout(panelConsultaLayout);
        panelConsultaLayout.setHorizontalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textFieldConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPaneTable, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
        );
        panelConsultaLayout.setVerticalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(textFieldConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPaneTable, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
        );

        tabbedPaneManutencao.addTab("Consulta", panelConsulta);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel1.setText("Código:");

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel10.setText("Código Pai:");

        jLabel2.setText("Produto:");

        comboBoxProduto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        comboBoxCodigoPai.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        jLabel3.setText("Nome:");

        jLabel4.setText("Código Processo:");

        jLabel5.setText("Ativo:");

        jLabel6.setText("Tem filho:");

        comboBoxTemFilho.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - Sim", "N - Não" }));

        jLabel9.setText("Objetivo:");

        textAreaObjetivo.setColumns(20);
        textAreaObjetivo.setRows(5);
        jScrollPane1.setViewportView(textAreaObjetivo);

        comboBoxAtivo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - Sim", "N - Não" }));

        javax.swing.GroupLayout jPanelManutencaoACadastroLayout = new javax.swing.GroupLayout(jPanelManutencaoACadastro);
        jPanelManutencaoACadastro.setLayout(jPanelManutencaoACadastroLayout);
        jPanelManutencaoACadastroLayout.setHorizontalGroup(
            jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel10)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel9))
                .addGap(83, 83, 83)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
                    .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                        .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboBoxProduto, 0, 398, Short.MAX_VALUE)
                                .addComponent(textFieldCodigoProcesso)
                                .addComponent(textFieldNome)
                                .addComponent(comboBoxCodigoPai, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(comboBoxTemFilho, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(comboBoxAtivo, javax.swing.GroupLayout.Alignment.LEADING, 0, 126, Short.MAX_VALUE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelManutencaoACadastroLayout.setVerticalGroup(
            jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(comboBoxProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCodigoProcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(textFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxCodigoPai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(comboBoxTemFilho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))
                .addContainerGap())
        );

        jScrollPaneManutencaoClienteA.setViewportView(jPanelManutencaoACadastro);

        javax.swing.GroupLayout panelAbaACadastroLayout = new javax.swing.GroupLayout(panelAbaACadastro);
        panelAbaACadastro.setLayout(panelAbaACadastroLayout);
        panelAbaACadastroLayout.setHorizontalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoClienteA)
        );
        panelAbaACadastroLayout.setVerticalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoClienteA)
        );

        tabbedPaneManutencao.addTab("Pagina A", panelAbaACadastro);

        jLabel7.setText("Consequência:");

        textAreaConsequenciaNaoUso.setColumns(20);
        textAreaConsequenciaNaoUso.setRows(5);
        jScrollPane3.setViewportView(textAreaConsequenciaNaoUso);

        jLabel8.setText("Link Vídeo:");

        textAreaLinkVideo.setColumns(20);
        textAreaLinkVideo.setRows(5);
        jScrollPane4.setViewportView(textAreaLinkVideo);

        jLabel11.setText("Periodicidade:");

        textAreaPeriodicidade.setColumns(20);
        textAreaPeriodicidade.setRows(5);
        jScrollPane2.setViewportView(textAreaPeriodicidade);

        javax.swing.GroupLayout panelAbaBCadastroLayout = new javax.swing.GroupLayout(panelAbaBCadastro);
        panelAbaBCadastro.setLayout(panelAbaBCadastroLayout);
        panelAbaBCadastroLayout.setHorizontalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(21, 21, 21)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
                    .addComponent(jScrollPane3)
                    .addComponent(jScrollPane4))
                .addContainerGap())
        );
        panelAbaBCadastroLayout.setVerticalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAbaBCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addContainerGap(81, Short.MAX_VALUE))
        );

        tabbedPaneManutencao.addTab("Pagina B", panelAbaBCadastro);

        javax.swing.GroupLayout panelAbaRelatorioLayout = new javax.swing.GroupLayout(panelAbaRelatorio);
        panelAbaRelatorio.setLayout(panelAbaRelatorioLayout);
        panelAbaRelatorioLayout.setHorizontalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 586, Short.MAX_VALUE)
        );
        panelAbaRelatorioLayout.setVerticalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Relatório", panelAbaRelatorio);

        toolBarManutencao.setFloatable(false);
        toolBarManutencao.setRollover(true);

        buttonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_form_magnify.png"))); // NOI18N
        buttonConsultar.setMnemonic('l');
        buttonConsultar.setText("Consultar");
        buttonConsultar.setFocusable(false);
        buttonConsultar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonConsultar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConsultarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonConsultar);

        buttonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_add.png"))); // NOI18N
        buttonNovo.setMnemonic('N');
        buttonNovo.setText("Novo");
        buttonNovo.setFocusable(false);
        buttonNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonNovo);

        buttonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_edit.png"))); // NOI18N
        buttonEditar.setMnemonic('E');
        buttonEditar.setText("Editar");
        buttonEditar.setFocusable(false);
        buttonEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonEditar);

        buttonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_delete.png"))); // NOI18N
        buttonExcluir.setMnemonic('x');
        buttonExcluir.setText("Excluir");
        buttonExcluir.setFocusable(false);
        buttonExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExcluirActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonExcluir);

        buttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/cancel.png"))); // NOI18N
        buttonCancelar.setMnemonic('C');
        buttonCancelar.setText("Cancelar");
        buttonCancelar.setFocusable(false);
        buttonCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonCancelar);

        buttonGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/accept.png"))); // NOI18N
        buttonGravar.setMnemonic('a');
        buttonGravar.setText("Gravar");
        buttonGravar.setFocusable(false);
        buttonGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonGravarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonGravar);

        buttonRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_side_list.png"))); // NOI18N
        buttonRelatorio.setMnemonic('R');
        buttonRelatorio.setText("Relatório");
        buttonRelatorio.setFocusable(false);
        buttonRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRelatorioActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonRelatorio);

        buttonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_left.png"))); // NOI18N
        buttonAnterior.setMnemonic('o');
        buttonAnterior.setText("Anterior");
        buttonAnterior.setFocusable(false);
        buttonAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnteriorActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonAnterior);

        buttonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_right.png"))); // NOI18N
        buttonProximo.setMnemonic('m');
        buttonProximo.setText("Próximo");
        buttonProximo.setFocusable(false);
        buttonProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProximoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonProximo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPaneManutencao)
            .addComponent(toolBarManutencao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPaneManutencao))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConsultarActionPerformed
        Consultar();
    }//GEN-LAST:event_buttonConsultarActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        CarregarNovoDados();
    }//GEN-LAST:event_buttonNovoActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        CarregarEditarDados();
    }//GEN-LAST:event_buttonEditarActionPerformed

    private void buttonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExcluirActionPerformed
        CarregarExcluirDados();
    }//GEN-LAST:event_buttonExcluirActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        CancelarOperacao();
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void buttonGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGravarActionPerformed
        GravarDados();
    }//GEN-LAST:event_buttonGravarActionPerformed

    private void buttonRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRelatorioActionPerformed
        tabbedPaneManutencao.setSelectedIndex(2);
    }//GEN-LAST:event_buttonRelatorioActionPerformed

    private void buttonAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAnteriorActionPerformed
        ProximaAba("Anterior");
    }//GEN-LAST:event_buttonAnteriorActionPerformed

    private void buttonProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProximoActionPerformed
        ProximaAba("Proximo");
    }//GEN-LAST:event_buttonProximoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CategoriaArvoreView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CategoriaArvoreView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CategoriaArvoreView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CategoriaArvoreView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CategoriaArvoreView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAnterior;
    private javax.swing.JButton buttonCancelar;
    protected javax.swing.JButton buttonConsultar;
    private javax.swing.JButton buttonEditar;
    private javax.swing.JButton buttonExcluir;
    private javax.swing.JButton buttonGravar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonProximo;
    private javax.swing.JButton buttonRelatorio;
    private javax.swing.JComboBox comboBoxAtivo;
    private javax.swing.JComboBox comboBoxCodigoPai;
    private javax.swing.JComboBox comboBoxProduto;
    private javax.swing.JComboBox comboBoxTemFilho;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JPanel jPanelManutencaoACadastro;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPaneManutencaoClienteA;
    private javax.swing.JScrollPane jScrollPaneTable;
    private javax.swing.JTable jTableConsulta;
    private javax.swing.JPanel panelAbaACadastro;
    private javax.swing.JPanel panelAbaBCadastro;
    private javax.swing.JPanel panelAbaRelatorio;
    private javax.swing.JPanel panelConsulta;
    private javax.swing.JTabbedPane tabbedPaneManutencao;
    private javax.swing.JTextArea textAreaConsequenciaNaoUso;
    private javax.swing.JTextArea textAreaLinkVideo;
    private javax.swing.JTextArea textAreaObjetivo;
    private javax.swing.JTextArea textAreaPeriodicidade;
    private javax.swing.JTextField textFieldCodigo;
    private javax.swing.JTextField textFieldCodigoProcesso;
    private javax.swing.JTextField textFieldConsultar;
    private javax.swing.JTextField textFieldNome;
    private javax.swing.JToolBar toolBarManutencao;
    // End of variables declaration//GEN-END:variables

    @Override
    public void CarregarEditarDados() {
        model.setActionScript("U");
        if (jTableConsulta.getSelectedRow() != -1) {
            textFieldCodigo.setEnabled(false);

            CategoriaArvoreModel categoriaModel = model.getCategoria(
                    UtilitariosCampos.getIntegerTable(jTableConsulta, 0));
            textFieldCodigo.setText(UtilitariosCampos.getIntegerText(categoriaModel.getCodigo()));
            comboBoxProduto.setSelectedItem(categoriaModel.getProduto().getCodigo() + " - " + categoriaModel.getProduto().getNome());
            textFieldCodigoProcesso.setText(categoriaModel.getCodigoProcesso());
            textFieldNome.setText(categoriaModel.getNome());

            comboBoxCodigoPai.setSelectedItem(categoriaModel.getCodigoPai().getCodigo() + " - " + categoriaModel.getCodigoPai().getNome());

            UtilitariosCampos.setRespostaComboBox(comboBoxAtivo, categoriaModel.getAtivo());
            UtilitariosCampos.setRespostaComboBox(comboBoxTemFilho, categoriaModel.getTemFilho());

            textAreaObjetivo.setText(categoriaModel.getObjetivo());
            textAreaPeriodicidade.setText(categoriaModel.getPeriodicidade());
            textAreaConsequenciaNaoUso.setText(categoriaModel.getConsNaoUso());
            textAreaLinkVideo.setText(categoriaModel.getLinkVideo());

            tabbedPaneManutencao.setSelectedIndex(1);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
    }

    /**
     * esse itemStateChanged sempre executa duas vezes, e ai gera duplicidade
     * dos dados, tem que fazer o tratamento abaixo
     */
    ItemListener comboBoxProdutoListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (!comboBoxProduto.getSelectedItem().toString().equals("ESCOLHER")
                    && e.getStateChange() == 2) {
                model.getCodigoPai().getModelComboBox().removeAllElements();
                model.getCodigoPai().getModelComboBox().addElement("ESCOLHER");
                model.getCodigoPai().getModelComboBox().addElement("0 - RAIZ");

                model.getCodigoPai().setActionScript("porProdutoTemFilho");
                model.getCodigoPai().getProduto().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));

                comboBoxCodigoPai.setModel(control.getDadosComboBoxModel(model.getCodigoPai()));

            }
        }
    };

    @Override
    public void CarregarDadosComboBox(CategoriaArvoreModel model, String actionScript) {
        ProdutoController produtoControl = new ProdutoController();
        ProdutoModel produtoModel = produtoControl.getModel();
        produtoModel.setActionScript("C");
        comboBoxProduto.setModel(produtoControl.getDadosComboBoxModel(produtoModel));
    }

    @Override
    public void CarregarNovoDados() {
        model.setActionScript("I");
        textFieldCodigo.setEnabled(false);
        tabbedPaneManutencao.setSelectedIndex(1);
    }

    @Override
    public void CarregarExcluirDados() {
        if (jTableConsulta.getSelectedRow() != -1) {
            CategoriaArvoreModel categoriaModel = model.getCategoria(
                    UtilitariosCampos.getIntegerTable(jTableConsulta, 0));
            categoriaModel.setActionScript("D");
            control.setDados(categoriaModel);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
        Consultar();
    }

    @Override
    public void CancelarOperacao() {
        LimparCampos();
        Consultar();
    }

    @Override
    public void CarregarVariaveis() {
        model.setCodigo(UtilitariosCampos.getIntegerText(textFieldCodigo));
        model.getProduto().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));
        model.getCodigoPai().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxCodigoPai));
        model.setCodigoProcesso(textFieldCodigoProcesso.getText());
        model.setNome(textFieldNome.getText());
        model.setAtivo(UtilitariosCampos.getRespostaComboBox(comboBoxAtivo));
        model.setTemFilho(UtilitariosCampos.getRespostaComboBox(comboBoxTemFilho));
        model.setObjetivo(textAreaObjetivo.getText());
        model.setPeriodicidade(textAreaPeriodicidade.getText());
        model.setConsNaoUso(textAreaConsequenciaNaoUso.getText());
        model.setLinkVideo(textAreaLinkVideo.getText());
    }

    @Override
    public void GravarDados() {
        if (model.getActionScript().equals("I") || model.getActionScript().equals("U")) {
            if (ValidaCampos()) {
                CarregarVariaveis();
                if (model.getActionScript().equals("I") && model.getCategoria(model.getCodigo()) != null) {
                    JOptionPane.showMessageDialog(panelConsulta, "Item já cadastrado na base de dados.");
                } else {
                    if (control.setDados(model)) {
                        Consultar();
                        LimparCampos();
                    }
                }
            }
        } else {
            JOptionPane.showMessageDialog(panelConsulta, "Você deve escolher uma ação clicando no botão Novo ou Editar.");
        }
    }

    @Override
    public void LimparCampos() {
        UtilitariosCampos.getLimpezaCampos(tabbedPaneManutencao);
    }

    @Override
    public void ProximaAba(String Movimento) {
        int a = tabbedPaneManutencao.getSelectedIndex();
        int quantidadeAba = tabbedPaneManutencao.getTabCount() - 1;
        switch (Movimento) {
            case "Anterior":
                if (a != 0) {
                    tabbedPaneManutencao.setSelectedIndex(a - 1);
                }
                break;
            case "Proximo":
                if (a != quantidadeAba) {
                    tabbedPaneManutencao.setSelectedIndex(a + 1);
                }
                break;
        }
    }

    @Override
    public void TamanhoColunaTable() {
        int posicao = 0;
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 50);//codigo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 150);//produto
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 120);//codigo processo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 350);//nome
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 550);//código processo pai
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 70);//ativo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 70);//tem filho
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 500);//objetivo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 500);//periodicidade
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 500);//consequencia do não uso
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 500);//link do video
    }

    @Override
    public void Consultar() {
        model.setActionScript("C");
        jTableConsulta.setModel(control.getDadosTableModel(model));
        tabbedPaneManutencao.setSelectedIndex(0);
        TamanhoColunaTable();
    }

    @Override
    public void CommitCampos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    KeyAdapter pesquisaDados = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            switch (e.getKeyCode()) {
                case KeyEvent.VK_ENTER://Botão Enter
                    model.setNome(textFieldConsultar.getText());
                    model.setActionScript("P");
                    jTableConsulta.setModel(control.getDadosTableModel(model));
                    TamanhoColunaTable();
                    break;
            }
        }
    };

    @Override
    public void InicializarListener() {
        textFieldConsultar.addKeyListener(pesquisaDados);
        comboBoxProduto.addItemListener(comboBoxProdutoListener);
    }

    @Override
    public void Start() {
        Consultar();
        InicializarListener();
        CarregarDadosComboBox(model, null);
        setExtendedState(MAXIMIZED_BOTH);
        model.setNomeTela(getTitle());
        setFiltroCampo();
    }

    @Override
    public boolean ValidaCampos() {
        if (!UtilitariosCampos.getValidarCampos(panelAbaACadastro)) {
            tabbedPaneManutencao.setSelectedIndex(1);
            return false;
        } else if (!UtilitariosCampos.getValidarCampos(panelAbaBCadastro)) {
            tabbedPaneManutencao.setSelectedIndex(2);
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void setFiltroCampo() {
        textFieldConsultar.setDocument(new setFiltroCampo(50, "LetraNumeroRealEspaco"));
        textFieldNome.setDocument(new setFiltroCampo(100, "LetraNumeroRealEspaco"));
        textFieldCodigoProcesso.setDocument(new setFiltroCampo(10, "NumeroInteiro"));
        textAreaObjetivo.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaPeriodicidade.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaConsequenciaNaoUso.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaLinkVideo.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
    }
}
